<?php

class My_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{

    protected $acl;

    public function __construct()
    {
        $this->acl = new My_Acl();
    }

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $rol = (Zend_Auth::getInstance()->hasIdentity()) ? 'user' : 'visitor';
        My_Logger::getInstance()->info('User rol: %s', $rol);

        //For this example, we will use the module name as the resource:
        $resource = $request->getModuleName();
        My_Logger::getInstance()->info('Accesing module: %s', $resource);
        if (!$this->acl->isAllowed($rol, $resource))
        {
            //If the user has no access we send him elsewhere by changing the request
            $request->setModuleName('default')
                ->setControllerName('login')
                ->setActionName('index')
                ->setParam('resource', $resource);
        }
    }

}